<?php
 mb_internal_encoding("utf-8");
 //gc_enabled();
 require "../document/class_corpus.php";
 require "../document/class_document.php";
 require "../document/class_document_xml.php";

 require "../files/tool_files_dirs.php";

 require "../misc/class_tag.php";
 require "../misc/tool_color.php";

 require "../tree/class_tree.php";
 require "../tree/class_tree_xhtml.php";
 require "../tree/class_structure.php";
 require "../tree/tool_tree.php";

 require "../array/tool_array.php";

 require "../pear_graph/tool_pear_graph.php";

 require "../maths/tool_maths.php";

 require "../string/tool_string.php";
 require "../string/class_segment.php";
 require "../string/class_suffixarray_new.php";
 require "../string/suffix_array.php";

 require "../pdo/class_sql_document.php";

//$dir="../xml/europa_complete_repair/";
//$lg_candidates=array("cs","da","de","el","en","es","et","fi","fr","hu","it","lt","lv","nl","pl","pt","sl","sw");
$lg_candidates=array("fr","en","da");
//$array_ids_europa=tool_corpus::get_unified_europa($dir,$lg_candidates);
$motif_lg="fr";
$lg="fr";

function complete_mt($_mt_vect,$_data){
  foreach($_data as $d){
    list($id_bloc,$nb_occ)=explode(":",$d);
    $_mt_vect[$id_bloc]=$nb_occ;    
  }
  return $_mt_vect;
}

function complete_mt2($_mt_vect,$_data){
  foreach($_data as $id_grain=>$d){
    $_mt_vect[$id_grain]=$d;
  }
  return $_mt_vect;
}

//$exp=new sql_experience("align_ecr_word");
$exp=new sql_experience("align_debug");
$array_obj_sql=$exp->reader_experience();
$res_all_count_bloc=array();
$global_array_corres=array();
foreach($lg_candidates as $lg){
  $start=microtime(true);
  $array_corres=$array_obj_sql["sql_rstr"]->reader_all2relative_id_doc($lg);
  $global_array_corres[]=$array_corres;
//  $array_obj_sql["sql_rstr"]->reader_all2count_bloc2($res_all_count_bloc,$lg,$array_corres);
  $array_obj_sql["sql_rstr"]->reader_all2count_doc($res_all_count_bloc,$lg,$array_corres);
  $end=microtime(true)-$start;
  echo "\n $lg :: $end\n";
}

$mt_vector=array_fill(1,count(reset($array_corres)),0);
$data_tmp=array();
$array_data=array();
$cpt=0;
$id_groupe=0;
$start=microtime(true);
foreach($res_all_count_bloc as $rep=>$array_occ){
  ++$id_groupe;
  foreach($array_occ as $occ){
    $array_data[]=array(
      "id_groupe"=>$id_groupe,
      "id_graphie"=>$occ[0],
      "id_lg"=>$occ[1],
      "type"=>0
    );
  }

  if(($id_groupe%500)==0){
    $array_obj_sql["sql_groupe"]->writer_array_values($array_data);
    unset($array_data);
    $array_data=array();
    ++$cpt2;
  }

  echo "\r$cpt2 - $id_groupe";
}

$array_obj_sql["sql_groupe"]->writer_array_values($array_data);
$end=microtime(true)-$start;
echo "\n total2 :: $end\n";
die();
?>
